<style lang="less">
.order{
    font-size: 16px;
    margin-left: 5px;
}
    .fold-enter-active, .fold-leave {
        transition: all .4s;
        opacity: 1;
    }
    .fold-enter, .fold-leave-active {
        transition: all .4s;
        opacity: 0;
    }
    .oc_popup{
        box-shadow: 0px 0px 20px 0px #9a9a9a;
        .oc_popup_title{
            border-bottom: 1px solid #e9eaec;
            padding: 14px 16px;
            line-height: 1;
            overflow: hidden;
            
            .oc_popup_title_t{
                float: left;
            }
            .oc_popup_title_x{
                float: right;
                
            }
        }
        .oc_popup_content{
            padding: 14px 16px;
            line-height: 1;
            .ivu-table-wrapper{
                height: 100% !important;
                .ivu-table-body{
                    height: calc(~"100% - 40px") !important;
                }
            }
        }
        .oc_popup_bottom{
            border-top: 1px solid #e9eaec;
            padding: 14px 16px;
            line-height: 1;
            button{
                float: right;
                margin-left: 10px;
            }
        }
    }
    .oc_popup:hover{
        
    }
    .icon {
        width: 17px; height: 17px;
        // vertical-align: -0.15em;
        fill: currentColor;
        overflow: hidden;
    }
    .icon.e{
        width: 14px; height: 14px;
        margin-left: -1px;
        margin-top:3px;
    }
    .icon.c{
        width: 17px; height: 17px;
        margin-left: -3px;
        margin-top: 2px;
    }
    .icon.g{
        width: 19px; height: 19px;
        margin-left: -4px;
        margin-top: 1px;
    }
    .icon.f{
        width: 19px; height: 19px;
        margin-left: -3px;
        margin-top: 1px;
    }
    .icon.t{
        width: 20px; height: 20px;
        margin-left: -4px;
        margin-top: 0px;
    }
    .icon.s{
        width: 16px; height: 16px;
        margin-left: -2px;
        margin-top: 2px;
    }
    .ss{
        background:url('../../styles/s.jpg') !important;
        background-position:center !important;
        .ivu-table-column-center{
            background:none !important;
        }
    }
    .ivu-table-tbody .demo-table-info-row td{
        background-color: #44caff !important;
        border-right: 1px solid #44caff !important;
        color: #fff;
    }
    // .ivu-form-item{
    //     margin-bottom:0px;
    // }
    .ivu-card-head-inner, .ivu-card-head p{
        height: auto;
        overflow: inherit;
    }
    .page-margin-top{
        margin-top:10px;
    }
    .ivu-modal-wrap{
        display: flex;
        align-items: center;
        justify-content: center;

        .ivu-modal{
            top: 0;
        }
    }
    .line-chart-con-tree{
        border: 1px solid #ddd;
    }
    .line-chart-con-tree:hover{
        // border:0;
    }
    .vertical-center-modal{
        display: flex;
        align-items: center;
        justify-content: center;

        .ivu-modal{
            top: 0;
        }
        .ivu-form-item {
            margin-bottom: 14px;
        }
    }
    .tree-box{
        position:relative;
        width: 20px;
        height: 100px;
        top: 50%;
        left: -2px;
        background: #9a9a9a;
        z-index: 999;
    }
</style>
<template>
    <div>
        <!-- <div class="tree-box">

        </div> -->
        <Row class="margin-top-10" :gutter="10">
            <Col :md="4" :lg="4">
                <Card :gutter="10">
                    <p slot="title" class="card-title">
                        <span>
                            <Icon type="ios-pulse"></Icon>
                            代理关系树
                        </span>
                        <span v-if="userFilter.ref_id!=''" style="float: right;">
                            <ButtonGroup size="small" shape="circle" style="">
                                <Button :type="userFilter.vbankers==false?'primary':'ghost'" @click="userFilter.vbankers=false;czPage();getUsers()">
                                    会员
                                </Button>
                                <Button :type="userFilter.vbankers==true?'primary':'ghost'" @click="userFilter.vbankers=true;czPage();getUsers()">
                                    代理
                                </Button>
                            </ButtonGroup>
                            <Checkbox v-model="userFilter.directly" @on-change="changeDirectly()" label="直属">直属</Checkbox>
                        </span>
                    </p>
                    <div class="line-chart-con-tree">
                        <oc-tree :list.sync='treeData' :func='nodeClick' :contextmenu='contextmenuClick' :is-open='false'></oc-tree>
                    </div>
                </Card>
            </Col>
            
            <Col :md="24" :lg="24">
                 <Card>
                    <p slot="title" class="card-title">
                        <Row class="" :gutter="10">
                            <Col :md="4" :lg="2">
                                <div style="margin-top: 2px;">
                                    <Icon type="ios-pulse"></Icon>
                                    {{this.$route.meta.title}}
                                </div>
                            </Col>
                            <Col :md="20" :lg="22">
                                <Form :model="formItem" label-position="left" inline>
                                    
                                    <Select v-model="model2" size="small" style="width:100px">
                                        <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option>
                                    </Select>
                                    :
                                    <Input size="small" v-model="queryData.user_name.value" style="width: 120px" placeholder="请输入用户名"></Input>
                                    
                                    <Button type="primary"  size="small" style="margin-top: 0px;" @click="search">查询</Button>
                                    <Button type="ghost"  size="small" style="margin-top: 0px;" @click="searchReset">重置</Button>                                 
                                    <Button type="primary"  size="small" @click="addm">新增用户</Button>
                                </Form>
                            </Col>
                        </Row>
                    </p>
                    <div class="line-chart-con">
                        <div style="position: relative;">
                            <Table border stripe :columns="title" @on-sort-change="dataDort" :data="data" :row-class-name="rowClass"></Table>
                            <Spin size="large" fix v-if="tl"></Spin>
                        </div>
                        
                        <Row class="margin-top-10" :gutter="10">
                            <Page :total="pgc" :current.sync="pgo" class-name="page-margin-top" show-elevator @on-change="pageC" show-sizer @on-page-size-change="pageX"></Page>
                        </Row>
                        
                    </div>
                </Card>
            </Col>
            
        </Row>
        <Modal title="编辑" v-model="modalEdit" class-name="vertical-center-modal" ok-text="保存" @on-ok="userEdit(mForm.index)">
            <Form :model="mForm" :label-width="80">
                <FormItem label="电话：">
                    <Input v-model="mForm.data.phone" placeholder="请输入电话号码"></Input>
                </FormItem>
                <FormItem label="QQ：">
                    <Input v-model="mForm.data.qq" placeholder="请输入QQ"></Input>
                </FormItem>
                <FormItem label="微信：">
                    <Input v-model="mForm.data.wx" placeholder="请输入微信"></Input>
                </FormItem>
                <FormItem label="备注：">
                    <Input v-model="mForm.data.comment" placeholder="请输入备注"></Input>
                </FormItem>
            </Form>
        </Modal>
        <Modal title="上级关系" v-model="modalRef" class-name="vertical-center-modal"  width="500">
            <div  style="position: relative;">
                <Table border stripe :row-class-name="rowClassName" :columns="modalRefTitle" :data="modalRefData"></Table>
                <Spin size="large" fix v-if="loading"></Spin>
            </div>
        </Modal>
        <Modal title="返点设置" v-model="modalRebate" class-name="vertical-center-modal"  width="500">
            <div  style="position: relative;">
                <Table border stripe :row-class-name="rowClassName" :columns="modalRebateTitle" :data="modalRefData"></Table>
                <Spin size="large" fix v-if="loading"></Spin>
            </div>
        </Modal>
        <Modal title="添加用户" v-model="modalAdd" class-name="vertical-center-modal" ok-text="添加" @on-ok="addUser()">
            <Form :model="addUserData" :label-width="80">
                <FormItem label="用户组：">
                    <Select v-model="addUserData.level_id" size="small" style="width:100px">
                        <Option v-for="item in groupList" :value="item.level" :key="item.level">{{ item.name }}</Option>
                    </Select>
                </FormItem>
                <FormItem label="用户名：">
                    <Input v-model="addUserData.user_name" placeholder="请输入用户名"></Input>
                </FormItem>
                <FormItem label="密码：">
                    <Input placeholder="请输入密码" disabled value="123456"></Input>
                </FormItem>
            </Form>
        </Modal>
        
        <!-- <button v-on:click="openDialog" >openDialog</button> -->
        <transition  name="fold">
            <div v-if="ocPopup" class="oc_popup" style="position: absolute;width: calc(100% - 20px);height: calc(100% - 20px);background: rgb(255, 255, 255);top: 10px;border-radius: 5px;z-index: 9999;">
                <div class="oc_popup_title"><div class="oc_popup_title_t">返点设置</div><a class="oc_popup_title_x" @click="selShow=false;ocPopup=false"><Icon type="close"></Icon></a></div>
                <div class="oc_popup_content" style="height: calc(100% - 100px);">
                    <div style="height: 100%;">
                        <Table ref="selection" @on-selection-change="selectionChange" border stripe height="200" :row-class-name="rowClassName" :columns="modalRebateTitle" :data.sync="modalRebateData"></Table>
                        <Spin size="large" fix v-if="loading"></Spin>
                    </div>
                </div>
                <div class="oc_popup_bottom">
                    <Form v-if="selShow" :model="xRebate" :label-width="145" style="float: left;">
                        <FormItem label="设置选中彩种返点比例：">
                            <Input v-model="xRebate.v" placeholder="请输入返点比例">
                                <Button slot="append" @click="setxz" style="margin-left: 0px;">确定设置</Button>
                            </Input>
                        </FormItem>
                    </Form>
                    <Button type="primary" :disabled="submitButton" @click="submitRebate">
                        提交
                    </Button>
                    <Button type="primary" @click="selShow=false;ocPopup=false">
                        取消
                    </Button>
                </div>
            </div>
        </transition>
    </div>
</template>

<script>
import '../../styles/fonts/iconfont'
import 'whatwg-fetch'
export default {
    components: {
        
    },
    computed: {
        
    },
    data () {
        return {
            order_param:'id',
            submitButton:false,
            gameInfo:{},
            selShow:false,
            tl:false,
            ocPopup:false,
            modalEdit:false,
            modalRef:false,
            modalAdd:false,
            loading:false,
            modalRebate:false,
            modalRefI:0,
            a:'',
            pgo:1,
            groupList:[],
            queryData:{
                user_name:{
                    operator:'=',
                    value:''
                }
            },
            xRebate:{
                a:{},
                v:0
            },
            setRebate:[],
            mForm:{
                index:0,
                query:{
                    uid:1
                },
                data:{
                        id:1,
                        phone:'',
                        qq:'',
                        wx:'',
                        // enable:false,
                        comment:''
                }
                
                
            },
            formItem:{
                input:''
            },
            pgc:0,
            userFilter:{
                order_param:'id',
                limit:'0,10',
                ref_id:'',
                directly:false,
                vbankers:false,
            },
            switchQuery:{
                directly:false,
                vbankers:false
            },
            addUserData:{  //添加会员
                level_id:-1,
                user_name:''
            },
            popup:false,
            cityList: [ //查询方式
                    {
                        value: '用户名',
                        label: '用户名'
                    }
                    
                ],
                model2: '用户名',
            data:[],
            modalRefData:[],
            treeData:[],
            modalRebateDataIndex:{},
            modalRebateData:[],
            modalRebateTitle:[
            {
                type: 'selection',
                width: 60,
                align: 'center',
                
            },
            {
                title:'彩种ID',
                key: 'id',
                align:'center',
            },
            {
                title:'彩种名称',
                key: 'name',
                align:'center',
            },
            {
                title:'彩种标签ID',
                key: 'bqid',
                align:'center',
            },
            {
                title:'彩种标签',
                key: 'bq',
                align:'center',
            },
            {
                title:'返点比例',
                key: '',
                align:'center',
                render: (h, params) => {
                    let _this=this
                    let u=JSON.parse(sessionStorage.user)
                    if(this.submitButton!==true){
                        if(this.xRebate.a[params.row.id]||this.xRebate.a[params.row.bqid]){
                            return h('div',this.xRebate.v)
                        }else{
                            return h('div',[
                                h('Input',{
                                    
                                        props:{
                                        value:_this.setRebate[params.index].rebate,
                                        placeholder:this.setIndex(params.row,params.index)
                                        },
                                        on: {
                                            input: function (e) {
                                                if(e!==''){
                                                    if(u.user_data.User.group_level>1){
                                                        if(e>params.row.aRebate){
                                                            _this.$Message.warning('返点比例设置不能超过最大返点');
                                                        }
                                                    }else if(u.user_data.User.group_level==1){
                                                        if(e>1){
                                                            _this.$Message.warning('返点比例设置不能不能大于1');
                                                        }
                                                    }
                                                    if(e<0){
                                                        _this.$Message.warning('返点比例设置不能不能小于0');
                                                    }
                                                    
                                                }
                                                _this.setRebate[params.index].rebate=e
                                            },
                                            // 'on-blur':this.iblur()
                                        }
                                })
                            ])
                        }
                    }else{
                        return h('div',this.xRebate.v)
                    }
                    
                           
                }
            },
            {
                title:'最大返点',
                key: 'aRebate',
                align:'center',
            },
        ],
            title:[
                {
                    title:'用户名',
                    key: 'user_name',
                    align:'center',
                    
                },
                {
                    title:'用户级别',
                    key: 'group_name',
                    align:'center',
                    
                },
                {
                    title:'推荐码',
                    key: 'rcode',
                    align:'center',
                    
                },
                {
                    title:'可用余额',
                    key: 'balance',
                    align:'center',
                    renderHeader: (h, params) => {
                           return h('div', [
                               h('span',params.column.title),
                               h('a',{
                                   class:'order',
                                   style:{
                                       color: this.userFilter.order_param==params.column.key?'':'#a0a0a0'
                                   },
                                   on: {
                                        click: () => {
                                            this.order (params.column.key)
                                        },
                                    },
                               },[
                                   h('Icon',{
                                        props:{
                                            type:"arrow-down-b"                                           
                                        }
                                   })
                               ])
                           ])//params.column.key
                    }
                },
                {
                    title:'历史付款',
                    key: 'all_paid_money',
                    align:'center',
                    renderHeader: (h, params) => {
                           return h('div', [
                               h('span',params.column.title),
                               h('a',{
                                   class:'order',
                                   style:{
                                       color: this.userFilter.order_param==params.column.key?'':'#a0a0a0'
                                   },
                                   on: {
                                        click: () => {
                                            this.order (params.column.key)
                                        },
                                    },
                               },[
                                   h('Icon',{
                                        props:{
                                            type:"arrow-down-b"                                           
                                        }
                                   })
                               ])
                           ])//params.column.key
                    }
                },
                {
                    title:'历史欠款',
                    key: 'all_un_paid_money',
                    align:'center',
                    renderHeader: (h, params) => {
                           return h('div', [
                               h('span',params.column.title),
                               h('a',{
                                   class:'order',
                                   style:{
                                       color: this.userFilter.order_param==params.column.key?'':'#a0a0a0'
                                   },
                                   on: {
                                        click: () => {
                                            this.order (params.column.key)
                                        },
                                    },
                               },[
                                   h('Icon',{
                                        props:{
                                            type:"arrow-down-b"                                           
                                        }
                                   })
                               ])
                           ])//params.column.key
                    }
                },
                {
                    title:'上次登录地点',
                    key: 'login_place',
                    align:'center',
                    
                },
                {
                    title:'上次登录时间',
                    key: 'login_time',
                    align:'center',
                    
                },
                {
                    title:'注册时间',
                    key: 'created',
                    align:'center',
                    
                },
                {
                    title:'操作',
                    key: '',
                    width: 180,
                    align:'center',
                    render: (h, params) => {
                           return h('div', [
                               h('Tooltip',{
                                   props: {
                                        content: '编辑',
                                        placement:'top'
                                    },
                               },[
                                   h('Button', {
                                        props: {
                                            type: 'ghost',
                                            size: 'small',
                                        },
                                        domProps: {
                                            innerHTML: `<svg class="icon e" aria-hidden="true"><use xlink:href="#icon-bianji"></use></svg>`
                                        },
                                        style: {
                                            width:'27px',
                                            height:'27px',
                                            marginRight: '2px',
                                            borderRadius: '27px'
                                        },
                                        on: {
                                            click: () => {
                                                // this.userEdit(params.row)
                                                this.mForm.index=params.index
                                                this.mForm.query.uid=params.row.uid
                                                this.mForm.data.id=params.row.id
                                                this.mForm.data.phone=params.row.phone
                                                this.mForm.data.qq=params.row.qq
                                                this.mForm.data.wx=params.row.wx
                                                // this.mForm.data.enable=params.row.enable
                                                this.mForm.data.comment=params.row.comment
                                                this.modalEdit = true
                                            },
                                        },
                                        
                                    }),
                               ]),
                                h('Tooltip',{
                                   props: {
                                        content: '重置密码',
                                        placement:'top'
                                    },
                               },[
                                    h('Button', {
                                        props: {
                                            type: 'ghost',
                                            size: 'small',
                                        },
                                        domProps: {
                                            innerHTML: `<svg class="icon c" aria-hidden="true"><use xlink:href="#icon-zhongzhimima"></use></svg>`
                                        },
                                        style: {
                                            width:'27px',
                                            height:'27px',
                                            marginRight: '2px',
                                            borderRadius: '27px'
                                        },
                                        on: {
                                            click: () => {
                                                this.patch(params.row,params.index)
                                            }
                                        }
                                    }),
                               ]),
                               h('Tooltip',{
                                   props: {
                                        content: '上级关系',
                                        placement:'top'
                                    },
                               },[
                                    h('Button', {
                                        props: {
                                            type: 'ghost',
                                            size: 'small',
                                        },
                                        domProps: {
                                            innerHTML: `<svg class="icon g" aria-hidden="true"><use xlink:href="#icon-jiguanshiyezhanghuchuli"></use></svg>`
                                        },
                                        style: {
                                            width:'27px',
                                            height:'27px',
                                            marginRight: '2px',
                                            borderRadius: '27px'
                                        },
                                        on: {
                                            click: () => {
                                                // alert(this.loading[params.index])
                                                this.modalRefI=params.row.id
                                                this.userRef(params.row.up_string)
                                            }
                                        }
                                    }),
                               ]),
                               h('Tooltip',{
                                   props: {
                                        content: '返点设置',
                                        placement:'top'
                                    },
                               },[
                                    h('Button', {
                                        props: {
                                            type: 'ghost',
                                            size: 'small',
                                        },
                                        domProps: {
                                            innerHTML: `<svg class="icon f" aria-hidden="true"><use xlink:href="#icon-iconfontjiduxiaoshoufandian"></use></svg>`
                                        },
                                        style: {
                                            width:'27px',
                                            height:'27px',
                                            marginRight: '2px',
                                            borderRadius: '27px'
                                        },
                                        on: {
                                            click: () => {
                                                this.upInput(params.row,params.index)
                                                this.getRebate(params.row,params.index)
                                            }
                                        }
                                    }),
                               ]),
                               h('Tooltip',{
                                   props: {
                                        // content: '踢下线',
                                        placement:'top',
                                        disabled:this.pdMap(params.row,params.index)
                                    },
                               },[
                                    h('Button', {
                                        props: {
                                            type: 'ghost',
                                            size: 'small',
                                            disabled:this.pdMap(params.row,params.index)
                                        },
                                        domProps: {
                                            innerHTML: `<svg class="icon t" aria-hidden="true"><use xlink:href="#icon-tiren"></use></svg>`
                                        },
                                        style: {
                                            width:'27px',
                                            height:'27px',
                                            marginRight: '2px',
                                            borderRadius: '27px'
                                        },
                                        on: {
                                            click: () => {
                                                this.kick(params.row.user_name)
                                            }
                                        }
                                    }),
                                    h('div', {
                                        props: {
                                            
                                        },
                                        slot:'content',
                                        domProps: {
                                            innerHTML: `<p>${Object.keys(params.row.online_map).length!=0?Object.keys(params.row.online_map)[0]+'在线':''}</p>`
                                        },
                                        style: {
                                            
                                        }
                                    }),
                               ]),
                                h('Tooltip',{
                                    props: {
                                            content: params.row.enable==false?'解冻':'冻结',
                                            placement:'top'
                                        },
                                },[
                                    h('Button', {
                                        props: {
                                            type: 'ghost',
                                            size: 'small',
                                        },
                                        domProps: {
                                            innerHTML: `<svg class="icon s" aria-hidden="true"><use xlink:href="${params.row.enable==false?'#icon-jiesuo':'#icon-msnui-lock'}"></use></svg>`
                                        },
                                        style: {
                                            width:'27px',
                                            height:'27px',
                                            marginRight: '2px',
                                            borderRadius: '27px'
                                        },
                                        on: {
                                            click: () => {
                                                this.lookSubordinate(params.row,params.index)
                                            }
                                        }
                                    }),
                                ])
                           ])
                    }
                },
            ],
            modalRefTitle:[
                {
                    title:'UID',
                    key: 'uid',
                    align:'center',
                    width:'120'
                },
                {
                    title:'用户名',
                    key: 'user_name',
                    align:'center',
                },
                {
                    title:'级别',
                    key: 'group_name',
                    align:'center',
                    width:'120'
                },
            ]
                
            
        }
    },
    methods: {
        init(){
            this.gameInfo=JSON.parse(sessionStorage.gameInfo)
            this.getTree()
            this.initRebate()
        },
        initRebate(){
            let arr=[]
            let arrSet=[]
            for(let i in this.gameInfo.lottery_set){
                let lgs=this.gameInfo.lottery_set[i]
                lgs.bq=''; lgs.bqid=''; lgs.rebate=0; lgs.aRebate=0;
                let robjs={
                    gid: this.gameInfo.lottery_set[i].id,
                    id: 0,
                    rebate: 0,
                    tab_id: 0,
                    uid: 0,
                    version: 0
                }
                if(this.gameInfo.lottery_set[i].id==2||this.gameInfo.lottery_set[i].name=="香港六合彩"||this.gameInfo.lottery_set[i].id==15||this.gameInfo.lottery_set[i].name=="急速六合一"){
                    for(let j=0;j<this.gameInfo.lottery_set[i].children.length;j++){
                        let obj={
                            enable:this.gameInfo.tab_set[this.gameInfo.lottery_set[i].children[j]].enable,
                            id:this.gameInfo.lottery_set[i].id,
                            name:this.gameInfo.lottery_set[i].name,
                            bq:this.gameInfo.tab_set[this.gameInfo.lottery_set[i].children[j]].name,
                            bqid:this.gameInfo.lottery_set[i].children[j],
                            rebate:0,
                            aRebate:0,
                        }
                        let robj={
                            gid: this.gameInfo.lottery_set[i].id,
                            id: 0,
                            rebate: 0,
                            tab_id: this.gameInfo.lottery_set[i].children[j],
                            uid: 0,
                            version: 0
                        }
                        arrSet.push(robj);
                        arr.push(obj);
                    }
                    
                }else{
                    arrSet.push(robjs);
                    arr.push(lgs);
                }
            }
            this.setRebate=arrSet
            this.modalRebateData=arr
        },
        order(key){
            this.userFilter.order_param=this.userFilter.order_param==key?'id':key
            this.getUsers()
        },
        dataDort(s){

        },
        submitRebate(){
            let u=JSON.parse(sessionStorage.user)
            let obj=this.setRebate
            let test=[]
            let _this=this
            for(let i=0;i<this.setRebate.length;i++){
                obj[i].rebate=parseFloat(this.setRebate[i].rebate)
                switch (true){
                    case obj[i].rebate<0:
                        test.push(this.setRebate[i]);
                        break;
                    case obj[i].rebate>1:
                        test.push(this.setRebate[i]);
                        break;
                    case obj[i].rebate>this.modalRebateData[i].aRebate&&u.user_data.User.group_level>1:
                        test.push(this.setRebate[i]);
                        break;
                }
            }
            
            if(test.length==0){

                this.$api.setRebate(obj).then(response=>{
                    response.json().then(responseJson=> {
                        // _this.ocPopup=false
                        if(responseJson.success==true){
                            _this.$Notice.success({
                                title: '返点设置成功',
                            });
                        }else{
                            _this.$Notice.error({
                                title: '返点设置失败',
                                desc: responseJson.error
                            });
                        }
                    })
                })
            }else{
                _this.$Notice.error({
                    title: '提交失败，请确认返点是否正确'
                });
            }
        },
        setxz(){
            let p=false
            let u=JSON.parse(sessionStorage.user)
            if(this.xRebate.v!=''){
                for(let key in this.xRebate.a){
                    this.modalRebateData[this.modalRebateDataIndex[key]].rebate=this.xRebate.v
                    this.setRebate[this.modalRebateDataIndex[key]].rebate=parseFloat(this.xRebate.v)
                    if(u.user_data.User.group_level>1){
                        if(this.xRebate.v>this.modalRebateData[this.modalRebateDataIndex[key]].aRebate||this.xRebate.v<0){
                            p=true
                        }
                    }else{
                        if(this.xRebate.v<0){
                            p=true
                        }
                    }
                }
                if(p){
                    this.$Message.warning('返点比例参数有误，请修改');
                }
            }else{
                this.$Message.warning('设置失败');
            }
            this.$refs.selection.selectAll(false);
            this.selShow=false
        },
        setIndex(r,i){
            if(r.id==2||r.name=="香港六合彩"||r.id==15||r.name=="急速六合一"){
                this.modalRebateDataIndex[r.bqid]=i
            }else{
                this.modalRebateDataIndex[r.id]=i
            }
        },
        selectionChange(selection){
            let obj={}
            if(this.submitButton!=true){
                if(selection.length!==0){
                this.selShow=true
                
                for(let i=0;i<selection.length;i++){
                    if(selection[i].id==2||selection[i].name=="香港六合彩"||selection[i].id==15||selection[i].name=="急速六合一"){
                        obj[selection[i].bqid]=true
                    }else{
                        obj[selection[i].id]=true
                    }
                    
                }
                
                
            }else{
                this.xRebate.a={}
                this.xRebate.v=0
                this.selShow=false
            }
            this.xRebate.a=obj
            }
        },
        qxInput(r,i){

        },
        addhtml(i){
            function fors(obj){
                let z=''
                let oKey=Object.keys(obj)
                for(let y=0;y<oKey.length;i++){
                    z+='<p>'+oKey[i]+'：在线</p>'
                }
            }
            
            if(Object.keys(this.data[i].online_map).length!=0){
                return fors(this.data[i].online_map)
            }else{
                return `<p></p>`
            }
        },
        upInput(r,i){
            let a_info=JSON.parse(sessionStorage.user)
            let up=r.up_string.split('>')
            if(up[up.length-2]==a_info.user_data.User.name){
                this.submitButton=false
            }else{
                this.submitButton=true
            }
        },
        //获取用户返点
        getRebate(r,i){
            this.initRebate()
            this.ocPopup=true
            let _this=this
            let lg=JSON.parse(sessionStorage.aRebate)
            this.$api.getOwn({uid:r.id}).then(response=>{
                response.json().then(responseJson=> {
                    for(let i=0;i<_this.modalRebateData.length;i++){
                        for(let j=0;j<responseJson.info.length;j++){
                            if(_this.modalRebateData[i].id==responseJson.info[j].UserRebate.gid&&responseJson.info[j].UserRebate.tab_id==_this.setRebate[i].tab_id){

                                _this.modalRebateData[i].rebate=responseJson.info[j].UserRebate.rebate

                                _this.setRebate[i].id=responseJson.info[j].UserRebate.id
                                _this.setRebate[i].rebate=responseJson.info[j].UserRebate.rebate
                                _this.setRebate[i].version=responseJson.info[j].UserRebate.version
                            }
                        }
                        for(let j=0;j<lg.info.length;j++){
                            if(_this.modalRebateData[i].id==lg.info[j].UserRebate.gid){
                                _this.modalRebateData[i].aRebate=lg.info[j].UserRebate.rebate
                            }
                        }
                        // _this.setRebate[i].ID=r.id
                        _this.setRebate[i].uid=r.id
                    }
                })
            })
        },
        changeDirectly(){
            this.czPage()
            this.getUsers()
        },
        getUsers(){
            let _this=this
            this.tl=true
            this.$api.getUsers(this.userFilter).then(response=>{
                response.json().then(responseJson=> {
                    _this.data=responseJson.data.Records
                    _this.pgc=responseJson.data.Count
                    _this.tl=false
                })
            }).catch(() => {
                
            });
        },
        lookSubordinate(r,i){
            let _this=this
            let p={
                query:{
                    uid:r.uid
                },
                data:{
                    id:r.id,
                    enable:r.enable==true?false:true,
                }
            }
            this.$api.setUsers(p).then(response=>{
                response.json().then(responseJson=> {
                    if(responseJson.success==true){
                        _this.$set(_this.data[i],"enable", responseJson.data.enable)
                        // _this.getUsers()
                    }else{
                        _this.$Message.error(responseJson.error);
                    }
                })
            })
        },
        patch(r,i){
            let _this=this
            let p={
                query:{
                    uid:`${r.uid}`
                }
            }
            this.$api.resetUserP(p).then(response=>{
                response.json().then(responseJson=> {
                    if(responseJson.success==true){
                        _this.$Notice.success({
                            title: '密码重置成功',
                            desc: responseJson.info
                        });
                    }else{
                        _this.$Message.error(responseJson.error);
                    }
                })
            })
        },
        pdMap(r,i){
            if(Object.keys(this.data[i].online_map).length==0){
                return true
            }else{
                return false
            }
                
        },
        rowClass(row, index){
            if (row.enable==false) {
                return 'ss';
            }
        },
        rowClassName(row, index){
            if (row.id === this.modalRefI) {
                return 'demo-table-info-row';
            }
            return '';
        },
        pageC(ev){
            let limit=this.userFilter.limit.split(",");
            this.userFilter.limit=`${(ev-1)*limit[1]},${limit[1]}`
            this.getUsers()
        },
        pageX(ev){
            this.userFilter.limit=`0,${ev}`
            this.getUsers()
        },
        czPage(){
            this.pgo=1
            let limit=this.userFilter.limit.split(",");
            this.userFilter.limit=`0,${limit[1]}`
        },
        getTree(){
            let _this=this
            this.$api.getNodeList().then(response=>{
                response.json().then(responseJson=> {
                    if(_this.treeData.length>0){
                        _this.$set(_this.treeData,0, responseJson.data)
                    }else{
                        _this.treeData.push(responseJson.data)
                    }
                })
            })
        },
        // 树，点击节点
        nodeClick(m){
            let p=JSON.parse(JSON.stringify(m))
            this.userFilter.ref_id=p.User.id
            // this.switchQuery.uper_id=p.User.UID
            this.czPage()
            this.getUsers()
        },
        // 树，右击事件
        contextmenuClick(m){

        },
        //编辑用户信息
        userEdit(i){
            let _this=this
            let data=this.data[i]
            let mf=this.mForm.data
            let fdata={
                query:{
                    uid:this.mForm.query.uid
                },
                data:{
                    id:mf.id
                }
            }
            if(mf.phone!==data.phone){
                fdata.data.phone=mf.phone
            }
            if(mf.qq!==data.qq){
                fdata.data.qq=mf.qq
            }
            if(mf.wx!==data.wx){
                fdata.data.wx=mf.wx
            }
            if(mf.comment!==data.comment){
                fdata.data.comment=mf.comment
            }
            if(Object.keys(fdata.data).length>1){
                this.$api.setUsers(fdata).then(response=>{
                    response.json().then(responseJson=> {
                        let obj = JSON.parse(JSON.stringify(data))
                        _this.$set(_this.data,i, obj)
                        if(responseJson.success==true){
                            obj.phone=responseJson.data.phone
                            obj.qq=responseJson.data.qq
                            obj.wx=responseJson.data.wx
                            obj.comment=responseJson.data.comment
                            obj.version=responseJson.data.version
                            _this.$Notice.success({
                                title: '修改成功',
                            });
                        }else{
                            _this.$Notice.error({title:responseJson.error});
                        }
                    })
                })
            }
            
        },
        //
        userRef(r){
            
            let _this=this
            this.loading=true
            this.$api.getRef(r).then(response=>{
                response.json().then(responseJson=> {
                    this.modalRef = true
                    _this.modalRefData=responseJson.data
                    _this.loading=false
                    
                })
            })
            
        },
        search(){
            if(this.$oc.ocqm(this.queryData)!=false){
                this.userFilter.query_params=this.$oc.ocqm(this.queryData)
                this.getUsers()
            }
        },
        searchReset(){
            if(this.$oc.ocqm(this.queryData)!=false){
                this.userFilter.query_params=''
                this.queryData.user_name.value=''
                this.getUsers()
            }
        },
        kick(u){
            let _this=this
            this.$api.kick(u).then(response=>{
                response.json().then(responseJson=> {
                    if(responseJson.success==true){
                        _this.$Message.success(responseJson.info);
                    }
                    
                })
            })
        },
        addm(){
            let u=JSON.parse(sessionStorage.user)
            this.groupList=[]
            let group = JSON.parse(sessionStorage.group)
            for(let i=0;i<group.length;i++){
                if(group[i].level==-1){
                    this.groupList.push(group[i])
                }
                if(group[i].level!=-2&&group[i].level>u.user_data.User.group_level){
                    this.groupList.push(group[i])
                }
            }
            this.modalAdd=true
            this.addUserData.level_id=-1
        },
        addUser(){
            let _this=this
            this.$api.addUser(this.addUserData).then(function(response) {
                response.json().then(function(responseJson) {
                    if(responseJson.success==true){
                        _this.$Notice.success({
                            title: `成功添加用户：${_this.addUserData.user_name}`,
                            desc: '默认密码：123456'
                        });
                        if(_this.addUserData.level_id>0){
                            _this.getTree()
                        }
                    }else{
                        _this.$Message.error(responseJson.info);
                    }
                })
                        
            })
        }
    },
    mounted(){
        this.init()
    },
    
};
</script>
